1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
/* Create AWT Button Example This java example shows how to create a Button using AWT Button class. */ import java.applet.Applet; import java.awt.Button; /* <applet code="CreateAWTButtonExample" width=200 height=200> </applet> */ public class CreateAWTButtonExample extends Applet{ public void init(){ /* * To create a button use * Button() constructor. */ Button button1 = new Button(); /* * Set button caption or label using * void setLabel(String text) * method of AWT Button class. */ button1.setLabel("My Button 1"); /* * To create button with the caption use * Button(String text) constructor of * AWT Button class. */ Button button2 = new Button("My Button 2"); //add buttons using add method add(button1); add(button2); } } |
Example Output
This doesn’t compile, it is misses the main argument.
Hey this is Applet
u have to use
appletviewer CreateAWTButtonExample.java
to run the program
For more help u can contact me on [email protected]
Explain all AWT and frame component and container with it’s all constructors or methods